<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1 user-scalable=0">
<link rel="stylesheet" href="<%=basePath%>assets/css/public.css">
<link rel="stylesheet" href="<%=basePath%>assets/css/page.css">
<link rel="stylesheet" href="<%=basePath%>assets/font-awesome-4.7.0/css/font-awesome.min.css">
<title>管理收货地址</title>
<script src="<%=basePath%>assets/js/jquery-1.8.3.min.js"></script>
<script src="<%=basePath%>assets/js/fontSize.js"></script>
<link rel="stylesheet" href="<%=basePath%>/assets/imgTools/helmet.css">
<link rel="stylesheet" href="<%=basePath%>/assets/noneOfCss/noneOfCss.css">
<style>
body {
	padding-top: 0.8rem;
}

.content {
	padding-bottom: 0.8rem;
	margin: 0;
}

.content ul li {
	background: #fff
}

.content ul li .dizhi {
	font-size: 0.24rem;
	line-height: 0.6rem;
	margin: 0 0.3rem
}

.content ul li p.xingming, .content ul li p.lxdd {
	width: 50%;
	float: left;
	font-size: 0.24rem;
	font-weight: bold;
	line-height: 0.6rem;
	padding: 0;
	text-indent: 0.3rem;
	padding-top: 0.1rem
}

.content ul li p.lxdd {
	text-align: right;
	width: 45%
}

.caozuo {
	height: 0.8rem;
	margin: 0 0.1rem;
}

.caozuo a {
	float: right;
	padding: 0 0.4rem;
	text-align: center;
	border-radius: 0.05rem;
	height: 0.5rem;
	line-height: 0.5rem;
	border: 1px solid #ccc;
	margin: 0.15rem;
	font-size: 0.22rem;
}

.caozuo div {
	font-size: 0.22rem;
	line-height: 0.8rem;
}

.caozuo div img {
	width: 0.26rem;
	height: 0.26rem;
	margin: 0.26rem 0.08rem 0 0.2rem;
	float: left;
}

.xinzengshdz {
	width: 100%;
	position: fixed;
	left: 0;
	bottom: 0
}

.xinzengshdz a {
	width: 100%;
	height: 0.8rem;
	background: #FF3F25;
	color: #fff;
	line-height: 0.8rem;
	font-size: 0.3rem;
	text-align: center;
	display: block
}

.xiugaishouhuoxinxi {
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.3);
	position: fixed;
	left: 0;
	top: 0;
	display: none
}

.xgCont {
	width: 80%;
	background: #fff;
	margin: 0 auto
}

.xgCont input, .xgCont textarea {
	width: 88%;
	line-height: 0.6rem;
	font-size: 0.2rem;
	border: 1px solid #ccc;
	margin: 0.1rem 4%;
	height: 0.6rem;
	padding: 0 2%
}

.xgCont textarea {
	height: auto
}

.anniu a {
	width: 30%;
	height: 0.6rem;
	line-height: 0.6rem;
	color: #fff;
	text-align: center;
	background: red;
	display: block;
	float: right;
	margin: 0.1rem
}
</style>
<script>
        $(function () {
            $('.content>ul').find('li').each(function () {
                $(this).find('.shezhimr').click(function () {
                    if($(this).find('img').attr('src') == '<%=basePath%>assets/images/wxz.png'){
                        $(this).find('img').attr('src','<%=basePath%>assets/images/xz.png');
                        $(this).parent().parent().siblings().find('.shezhimr').find('img').attr('src','<%=basePath%>assets/images/wxz.png')
                        $.ajax({
							url: $("#basePath").val()+"app/updateDefaultAddress",
					        dataType: "json",
					        type: "post",
					        data: {
					        	"addressId":$(this).find('img').attr('id')
					        },
					        success: function (data) {
					        }
					    })
                        
                    }else {
<%--                         $(this).find('img').attr('src','<%=basePath%>assets/images/wxz.png') --%>
                    }
                });
                $(this).find('.caozuo').find('.shanchushdz').click(function () {
                    $(this).parent().parent().remove()
                });
        	});
        });
        //编辑收货地址
        function toUpdateAddress(addressId){
        	window.location.href=$("#basePath").val()+"app/toUpdateAddress?addressId="+addressId;
        };
    </script>
</head>
<body>
	<input id="basePath" type="hidden" value="<%=basePath%>">
	<div class="header">
		<a class="returnInfo" href="<%=basePath%>app/toPersonCenter"><i class="fa fa-angle-left"></i></a>
		管理收货地址
	</div>
	<div class="content">
		<ul>
			<c:forEach items="${addressList}" var="addressList">
				<li class="border-bottom-8">
					<p class="xingming">${addressList.userName}</p>
					<p class="lxdd">${addressList.userPhone}</p>
					<div class="clear"></div>
					<p class="dizhi border-bottom-1">
						${addressList.province},
						${addressList.city},
						<c:if test="${not empty addressList.county}">
							${addressList.county},
						</c:if>
						${addressList.address}
					</p>
					<div class="caozuo clearFirx">
						<div class="float_l shezhimr">
							<c:choose>
								<c:when test="${addressList.isDefault eq 1}">
									<img id="${addressList.addressId}"
										src="<%=basePath%>assets/images/xz.png" alt="">设置为默认地址
		                	</c:when>
								<c:otherwise>
									<img id="${addressList.addressId}"
										src="<%=basePath%>assets/images/wxz.png" alt="">设置为默认地址
		                	</c:otherwise>
							</c:choose>
						</div>
						<a href="javascript:;" class="shanchushdz"
							onclick="delAddress(${addressList.addressId})">删除</a> <a
							href="javascript:;" class="bianjishdz"
							onclick="toUpdateAddress(${addressList.addressId})">编辑</a>
					</div>
				</li>
			</c:forEach>
		</ul>
	</div>
	<div class="noSJ" style="display: none;">
		<img src="<%=basePath%>assets/images/bcz.png" alt="">
		<h3 style="font-size: 1.17em;">您还没有收货地址,请点击下面新增收货地址吧~</h3>
	</div>
	<div class="xinzengshdz">
		<a href="<%=basePath%>jsp/app/addAddress.jsp">新增收货地址</a>
	</div>
<script type="text/javascript">
	var obj = "${addressList}";
	if(obj == "[]"){
		$(".noSJ").css("display","block");
	}
	function delAddress(addressId){
		$.ajax({
	    	url: $("#basePath").val()+"app/delAddress",
	        timeout: 300000,
	        dataType: "json",
	        type: "post",
	        data: {
	        	"addressId":addressId
	        },success : function(data) {
	        	window.location.href=$("#basePath").val()+"app/getAddressList";
	        }
	    })
	}
</script>
</body>
</html>